import 'package:oktoast/oktoast.dart';

import 'package:fun/entity/ar_guide.dart';
import 'package:fun/model/base.dart';
import 'package:fun/service/ar.dart';

///
/// ar模型
///
/// @author zzzz1997
/// @created_time 20200715
///
class ArModel extends BaseModel {
  // 商品列表
  List<ArGuide> _arGuides = [];

  // 获取商品列表
  List<ArGuide> get arGuides => _arGuides;

  // 页码
  int _page = 1;

  // 没有更多
  bool _noMore = false;

  // 获取没有更多
  bool get noMore => _noMore;

  ///
  /// 初始化
  ///
  init() async {
    _page = 1;
    _noMore = false;
    await load(() async {
      _arGuides = await ArService.getArGuide();
    });
  }

  ///
  /// 加载更多
  ///
  loadMore() async {
    await load(() async {
      var list = await ArService.getArGuide(page: _page + 1);
      if (list.isNotEmpty) {
        _page++;
        _arGuides += list;
      } else {
        _noMore = true;
        showToast('没有更多了～');
      }
    });
  }
}
